const StatBehavior = require('../modules/stat_behavior')
const IP2Region = require('ip2region').default
const query = new IP2Region({
  disableIpv6: true,
});

module.exports = class StatService {
  async getIpVisitList({date, limit=10 }) {
    const allUvList = await StatBehavior.getIpVisitCount({date})
    return allUvList.slice(0, limit).map(item => {
      const dataValues = item.dataValues
      return {
        ...dataValues,
        ...query.search(dataValues.ip)
      }
    })
  }
}